class Preference < Hash
  
  PREFERENCE_FILE = RAILS_ROOT+"/config/preferences.yml"
  
  def initialize
    super
    
    load
    
    if self["title"].nil?
      self["title"] = "GrabTheMic"
    end
    
    if self["subtitle"].nil?
      self["subtitle"] = "By the People, For the People"
    end
    
    if self["links_open_new_window"].nil?
      self["links_open_new_window"] = false
    end
    
    if self["admin_email"].nil?
      self["admin_email"] = "me@domain.com"
    end
    
    if self["from_email"].nil?
      self["from_email"] = "alerts@domain.com"
    end
    
    if self["url"].nil?
      self["url"] = "http://www.grabthemic.org/"
    end
  end
  
  def load
    self.clear
    if File.exists?(PREFERENCE_FILE)
      File.open(PREFERENCE_FILE) do |f|
        data = YAML.load f
        self.merge! data
      end
    end    
  end
  
  def save
    File.open(PREFERENCE_FILE,"w") do |f|
      YAML.dump self, f
    end  
  end
  
  
      
end